<template>
	<view class="conter">
		<header-box :title="title"></header-box>

		<view class="conter-text">
			<view class="bgc">
				<view class="shop-heig">
					<text>商品</text>
					<view class="">
						<input type="text" v-model="list.name" placeholder="请输入商品名称" />
					</view>
				</view>

				<!-- <view @tap="goHome('/pages/shopping/select')" class="text-heig">
					<text>单位</text>
					<view class="">
						{{monad}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</view>
				
				<view @tap="goHome('/pages/shopping/classShopp')" class="text-heig">
					<text>分类</text>
					<view class="">
						{{className}}
						<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
					</view>
				</view> -->
				<view class="left-box">
					<text>商品图片</text>
					<view class="" style="margin-top: 20rpx;">
						<u-upload max-count="1" :file-list="fileList" @on-success="goodsImage" @on-remove="removeImage"
							:action="action" width="200rpx" height="200rpx"></u-upload>
					</view>
				</view>
			</view>
		</view>

		<view class="add bg-gradual-green" @click="addShopping">
			确定修改
		</view>


		<!-- <u-loading show="loading" size="60"></u-loading> -->


	</view>
</template>

<script>
	import headerBox from '../../components/header/header.vue'

	export default {
		components: {
			headerBox
		},
		data() {
			return {
				title: '修改商品',
				showNum: false,
				show: false,
				mode: 'date',
				monad: '请选择单位',
				action: this.$IMG_URL,
				// pathList: [],
				pathList: '',
				shoppinName: '',
				classId: '',
				methodsNum: '',
				init: '',
				list: {},
				fileList: [],
				className: '请选择分类',
			}
		},
		onLoad(e) {
			// console.log('跳转方法', JSON.parse(e.item))
			// this.list = JSON.parse(e.item)
		},
		onShow() {
			console.log('单位', this.monad)
			console.log('单位id', this.fileList)

			this.list = uni.getStorageSync('item')
			var obj = {
				url: this.list.image
			}
			this.fileList.push(obj)
		},
		methods: {
			change(e) {
				console.log(e);
			},

			goodsImage(e) {
				// this.pathList.push(e.data)
				this.list.image = e.data
			},

			removeImage() {
				this.list.image = ''
			},

			goHome(url) {
				uni.navigateTo({
					url,
				})
			},


			async addShopping() {
				// 使用 v-if 判断 添加商品等于 methodsNum = 2 
				// 使用 v-if 判断 编辑商品等于 methodsNum = 1
				
				uni.showLoading({
					title: '请求中'
				})
				
				const res = await this.$u.post("api/jinxiao.Goods/edits", {
					name: this.list.name,
					image: this.list.image,
					id: this.list.id,
					// classify_id: this.classId,
				});
				
				uni.hideLoading()
				
				if (res.code !== 1) return this.$tools.msg(res.msg)
				
				
				this.$tools.msg(res.msg)
				setTimeout(function() {
					uni.navigateBack({
						delta: 1
					})
				},2000)
				// console.log('请求成功',res)

			}
		}
	}
</script>

<style lang="scss" scoped>
	.conter {
		width: 100%;
		height: 100%;
		position: relative;
	}

	.conter-text {
		padding: 30rpx;

		.bgc {
			width: 100%;
			// height: 200rpx;
			padding: 0 30rpx;
			border-radius: 10rpx;
			background-color: #FFFFFF;

			.text-heig {
				height: 108rpx;
				line-height: 108rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: 1rpx solid #F0F0F0;
			}


			.left-box {
				height: 310rpx;
				padding-top: 30rpx;

				/deep/.u-list-item.data-v-3d60ab68 {
					margin: 0 !important;
				}
			}


			.shop-heig {
				height: 144rpx;
				padding-top: 40rpx;

				view {
					margin-top: 24rpx;
					border-bottom: 1rpx solid #F0F0F0;
				}
			}
		}
	}

	.add {
		position: fixed;
		bottom: 30rpx;
		left: 50%;
		width: 90%;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 45rpx;
		transform: translateX(-50%);
		text-align: center;
		color: #FFFFFF;
		font-size: 32rpx;
	}


	.box-btn {
		height: 100rpx;
		width: 90%;
		margin: 0 auto;
		line-height: 100rpx;
		margin-top: 20rpx;
		border-top: 1rpx solid #F0F0F0;
		display: flex;
		justify-content: space-around;

		view {
			width: 50%;
			text-align: center;
			border-right: 1rpx solid #F0F0F0;
		}

		view:last-child {
			border-right: 0;
		}
	}
</style>
